package com.anrongtec.zcpt.view;

import java.util.List;

import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.module.Type;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class FloatSearchView extends LinearLayout {

	private TextView tv_view_float_search;
	private ImageView iv_view_float_search;
	private LinearLayout view_float_search_unexpand;
	private SearchTagView stv;
	private Context context;
	private boolean isExpand =false;//是否展开

	public FloatSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
		super(context, attrs, defStyleAttr, defStyleRes);
		this.context = context;
	}

	public FloatSearchView(Context context, AttributeSet attrs, int defStyleAttr) {
		this(context, attrs, defStyleAttr, 0);
	}

	public FloatSearchView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public FloatSearchView(Context context) {
		this(context, null);
		initDefaultView();
		initClickLinister();
	}

	private void initDefaultView() {
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT);
		setLayoutParams(params);
		setOrientation(LinearLayout.VERTICAL);
		setVisibility(View.GONE);
		setBackgroundColor(getResources().getColor(R.color.grey));
		setAlpha(180);
		// 搜索框有两项 一项是伸缩的TextView,另一项是展开搜索列表 也就是 searchTagView
		view_float_search_unexpand = (LinearLayout) View.inflate(context, R.layout.view_float_search_unexpand, null);
		tv_view_float_search = (TextView) view_float_search_unexpand.findViewById(R.id.tv_view_float_search);
		iv_view_float_search = (ImageView) view_float_search_unexpand.findViewById(R.id.iv_view_float_search);
		addView(view_float_search_unexpand);
		stv = new SearchTagView(context);
		addView(stv);
		stv.setVisibility(View.GONE);
	}

	public void setTagList(List<List<Type>> list) {
		stv.setSourceData(list);
	}

	private void initClickLinister() {
		iv_view_float_search.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
					expandSearchView();
			}
		});
	}

	/**
	 * 显示折叠起来的搜索View
	 */
	public void showUnexpandSearchView(CharSequence text) {
		setVisibility(View.VISIBLE);
		showSearchTextView();
		setSearchText(text);
	}

	public void showSearchTextView() {
		view_float_search_unexpand.setVisibility(View.VISIBLE);
		if (null != stv) {
			stv.setVisibility(View.GONE);
		}
	}

	public void expandSearchView() {
		stv.setVisibility(View.VISIBLE);
		view_float_search_unexpand.setVisibility(View.GONE);
	}

	public void setSearchText(CharSequence text) {
		tv_view_float_search.setText(text);
	}

	// public void setSearchTagView(SearchTagView tagView) {
	// if (null != tagView) {
	// this.stv = tagView;
	// addView(stv);
	// stv.setVisibility(View.GONE);
	// }
	// }
}
